﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GtsServer.DAL;
using GtsServer.Model;
using System.Data;
using GtsServer.Common;

namespace GtsServer.Manage.Controller
{
    public class PrizeRecordController
    {
        PrizeRecordDAL dal = new PrizeRecordDAL();
        public List<PrizeRecord> GetList(int pageIndex, int pageSize, out int count, string strWhere = "")
        {
            count = 0;
            List<PrizeRecord> list = new List<PrizeRecord>();
            if (!string.IsNullOrEmpty(strWhere))
                strWhere = " pr.OrderAccount = '" + strWhere + "'";
            DataSet ds = dal.GetAllList(pageIndex, pageSize, strWhere);
            count = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
            list = IListDataSet.DataSetToIList<PrizeRecord>(ds, 0).ToList();
            return list;
        }

        public bool BatchEdit(string startTime, string endTime, string state1, string state2,string userAccount)
        {
            return dal.BatchEdit(startTime, endTime, state1, state2, userAccount);
        }

        public List<PrizeRecordShow> GetListBySelect(int pageIndex, int pageSize, out int count, int SelectByID, string StartTime, string EndTime, string strWhere = "")
        {
            count = 0;
            List<PrizeRecordShow> list = new List<PrizeRecordShow>();
            if (!string.IsNullOrEmpty(strWhere))
                switch (SelectByID)
                {
                    case 1://通过时间段来查询
                        strWhere = " pr.CreateTime > '" + StartTime + "' and pr.CreateTime<'" + EndTime + "'";
                        break;
                    case 2://通过IMSI来查询
                        strWhere = " u.IMSI = '" + strWhere + "'";
                        break;
                    case 3://通过用户QQ来查询
                        strWhere = " pr.UserQQ = '" + strWhere + "'";
                        break;
                    case 4://通过订单号来查询
                        strWhere = " pr.OrderAccount = '" + strWhere + "'";
                        break;
                    case 5://通过用户电话来查询
                        strWhere = " pr.UserPhone = '" + strWhere + "'";
                        break;
                    case 6://通过IMSI来查询
                        strWhere = " u.UserAccount = '" + strWhere + "'";
                        break;
                    default:
                        break;
                }

            DataSet ds = dal.GetAllList(pageIndex, pageSize, strWhere);
            count = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
            list = IListDataSet.DataSetToIList<PrizeRecordShow>(ds, 0).ToList();
            return list;
        }
        public bool UpdateState(PrizeRecord model)
        {
            return dal.UpdateState(model);
        }
    }
}
